#!/usr/bin/env bash
deviceId=$1
appName=$2
lastTime=$3
if [ $# != 3 ]; then
	echo "sh battery-monkey.sh deviceId appName lastTime(s)"
	exit;
fi
currentDir=$(cd "$(dirname "$0")"; pwd)

runInfoFile=$currentDir/target/android-info/run-info.txt
mkdir -p $currentDir/target/android-info
#记录本次运行的信息
echo "MONKEY" > $runInfoFile
date '+%s' >> $runInfoFile

echo "start monitor "$appName" ..."
sh $currentDir/src/main/resources/get-android-pid.sh ${deviceId} ${appName}
echo "release monkey on "$appName" ..."
sh ${currentDir}/src/main/resources/get-android-monkey.sh $deviceId $appName 20000 &
sleep $lastTime
echo "kill all scripts and monkey"
sh ${currentDir}/src/main/resources/kill-scripts-android.sh
echo "analyse the result..."
cd ${currentDir}
/Users/apple/work/apache-maven-3.2.2/bin/mvn install -DtestFile=testng-android.xml
mv $currentDir/target $currentDir/target-$appName
echo "sleep 5 seconds..."
sleep 5
